#include <stdlib.h>

#include "dependances.h"

#include "constantes_et_macros.h"



void init_tab_dependances(struct tab_dependances* tab,
                          const unsigned int taille)
{
    tab->nb_elements = 0;
    if(!(tab->tab = (struct dependance*)malloc(taille * sizeof(struct dependance))))
        exit(EXIT_MALLOC);
}



void detruire_tab_dependances(struct tab_dependances* tab)
{
    int i;

    for(i = 0;  i < tab->nb_elements;  i++)
        detruire_tab_dyn_id(&tab->tab[i].tab_id);
    if(tab->nb_elements > 0)
        free(tab->tab);
}



void init_dependance(struct tab_dependances* tab,
                     const unsigned int id_region,
                     const unsigned int nb_dependances)
{
    init_tab_dyn_id(&tab->tab[tab->nb_elements].tab_id, nb_dependances);
    tab->tab[tab->nb_elements].tab_id.nb_elements = 0;
    tab->tab[tab->nb_elements].id_region = id_region;
    tab->nb_elements++;
}



void ajouter_dependance(struct tab_dependances* tab, const unsigned int id_region)
{
    ajouter_id(&tab->tab[tab->nb_elements - 1].tab_id, id_region);
}
